import { reactive } from "vue";
import router from "@/router";
import { useCurrentUserStore } from "@/stores/currentUser";
import { storeToRefs } from "pinia";

const store = useCurrentUserStore();
const { portalMenuIndex } = storeToRefs(store);

export const _$ = reactive({
  state: {
    activeIndex: portalMenuIndex,
  },
});

export const $ = {
  onChangeMenu(index) {
    localStorage.setItem("ats-portal-menu-index", index);
  },

  onHandleClick(cmd) {
    if (cmd === "profile") {
      router.push("/manage/person/base");
    } else if (cmd === "avatar") {
      router.push("/manage/person/avatar");
    } else if (cmd === "password") {
      router.push("/manage/person/modify-pwd");
    } else if (cmd === "logout") {
      router.push("/logout");
    }
  },
};

export const to = {
  toLogout() {
    router.push("/login");
  },
};
